package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.investigate.BpSafeTableType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author ZhangDong
 * @Date 2020/12/1 15:04
 */
public interface BpSafeTableTypeDao extends JpaRepository<BpSafeTableType, Long> {

    @Query(value = "select 1 from wwyt_bp_safe_table_type t where type_name=:typeName and delete_flag= '0' limit 1",
            nativeQuery = true)
    Integer existsByTypeName(String typeName);

    List<BpSafeTableType> findByParentId(Long parentId);

    List<BpSafeTableType> findByParentIdNot(Long parentId);

    List<BpSafeTableType> findByParentIdIn(List<Long> parentIdList);

    @Query("update BpSafeTableType t set t.deleteFlag ='1' where t.id in (:idList)")
    @Modifying
    void deleteAllByIdIn(List<Long> idList);

}
